const express = require("express");
const Login = require("../middleware/login");
// 创建登陆应用
const userApp = express();
// 用户列表
userApp.post("/", [Login.login], (req, res, next) => {
    res.json({
        userList: req.userList,
        total: req.total
    });
});
// 用户列表
userApp.get("/userlist", [Login.UserList], (req, res, next) => {
    res.json({
        userList: req.userList,
        total: req.total
    });
});
// 删除用户
userApp.post("/delUser", [Login.delUser], (req, res) => {
    if (req.affectedRows > 0) {
        res.json({
            code: 200,
            msg: "删除成功",
        });
    } else {
        res.json({
            code: 404,
            msg: "删除失败",
        });
    }
});
// 用户添加
userApp.post("/userAdd", [Login.userAdd], (req, res) => {
    if (req.insertId) {
        res.json({
            code: 200,
            msg: "添加成功",
        });
    } else {
        res.json({
            code: 404,
            msg: "添加失败",
        });
    }
});
// 编辑用户信息
userApp.post("/editUser", [Login.editUser], (req, res) => {
    if (req.affectedRows > 0) {
        console.log(req.affectedRows);
        res.json({
            code: 200,
            msg: "用户编辑成功",
        });
    } else {
        res.json({
            code: 404,
            msg: "用户编辑失败",
        });
    }
});
module.exports = userApp;